package aliyun;

import aviator.StrUtils;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.cloudapi.sdk.client.ApacheHttpClient;
import com.alibaba.cloudapi.sdk.enums.HttpConnectionModel;
import com.alibaba.cloudapi.sdk.enums.HttpMethod;
import com.alibaba.cloudapi.sdk.enums.ParamPosition;
import com.alibaba.cloudapi.sdk.enums.Scheme;
import com.alibaba.cloudapi.sdk.model.ApiRequest;
import com.alibaba.cloudapi.sdk.model.ApiResponse;
import com.alibaba.cloudapi.sdk.model.HttpClientBuilderParams;
import com.alibaba.fastjson.JSON;
import org.apache.http.util.EntityUtils;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author zhanglu
 * @project JavaBase
 * @description
 * @date 2023/1/28 11:10
 */
public class ResumeDemo extends ApacheHttpClient{

    public void test(){
        HttpClientBuilderParams httpParam = new HttpClientBuilderParams();
        httpParam.setAppKey("204149167");
        httpParam.setAppSecret("aOAcrK64tHo2QgNQHjgsWrBeqAfTDEOG");
        super.init(httpParam);
        String host = "resumesdk.market.alicloudapi.com";
        String path = "/ResumeParser";
        String appcode = "4689ae04c89f4e4eb2be6b29699e8134";
        String fname = "/Users/zhanglu/Library/Containers/com.tencent.xinWeChat/Data/Library/Application Support/com.tencent.xinWeChat/2.0b4.0.9/c9a1c762ab6161f8ffce2831a28327a2/Message/MessageTemp/178d20fc7069efc975d25ccf18e6eaf4/File/QA工程师(南京-鼓楼区)(49479509)卞东浩-25岁-3年经验-质量管理-猎聘简历.docx";
        String data = cn.hutool.core.codec.Base64.encode(new File(fname));
        Map<String, Object> params = new LinkedHashMap<>();
        params.put("file_name", "QA工程师(南京-鼓楼区)(49479509)卞东浩-25岁-3年经验-质量管理-猎聘简历.doc");
        params.put("file_cont", data);
        params.put("need_avatar", 0);
        params.put("ocr_type", 1);
        ApiRequest request = new ApiRequest(HttpMethod.POST_BODY , path, JSON.toJSONString(params).getBytes(StandardCharsets.UTF_8));
        request.setHttpConnectionMode(HttpConnectionModel.MULTIPLE_CONNECTION);
        request.setHost(host);
        request.setScheme(Scheme.HTTP);
        ApiResponse apiResponse = sendSyncRequest(request);

        System.out.println(StrUtil.str(apiResponse.getBody(), CharsetUtil.UTF_8));
    }

    public static void main(String[] args) {
        new ResumeDemo().test();
    }

}
